package com.zhangx.study.demo.dynamicconfig.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.reactive.context.StandardReactiveWebEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ConfigController
 * @Description 获取配置信息
 * @Author zhangx
 * @Date 2021/4/12 8:22
 **/
@RestController
@RequestMapping("config")
public class ConfigController {

    @Autowired
    private Environment environment;

    @GetMapping(value = "get",produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8" )
    public JSONObject get(){
        JSONObject result = new JSONObject();
        String userName = environment.getProperty("cn.username");
        result.put("cn.username",userName);
        return result;
    }
}
